# -*- coding: utf-8 -*-
import json

def getCompanyCertList(request):
    #1数据
    request.cursor_standard.execute(request.formatSql('''
        select 
            company_apt.*,
            dict_company_apt.* ,
            dict_company_apt_level.level_name as qual_level_name
        from standard.company_apt
        left join standard.dict_company_apt on dict_company_apt.id = company_apt.apt_dict_id
        left join standard.dict_company_apt_level on company_apt.level_id = dict_company_apt_level.level_id
        where  company_apt.company_name like '%${company_name}%'
        and ('${cert_dict_id}' = '' or company_apt.apt_dict_id = '${cert_dict_id}' )
        limit ${start} , ${rows}
    '''))
    rows = request.cursor_standard.fetchall()

    #2页码
    request.cursor_standard.execute(request.formatSql('''
        select
            count(*) as total
        from standard.company_apt
        left join standard.dict_company_apt on dict_company_apt.id = company_apt.apt_dict_id
        left join standard.dict_company_apt_level on company_apt.level_id = dict_company_apt_level.level_id
        where  company_apt.company_name like '%${company_name}%'
        and ('${cert_dict_id}' = '' or company_apt.apt_dict_id = '${cert_dict_id}' )
    '''))
    total = request.cursor_standard.fetchone()['total']
    return json.dumps({'rows':rows,'total':total}, ensure_ascii=False)